package com.tian.service.impl;

import com.tian.convert.ChargeRecordConvertUtil;
import com.tian.dto.ChargeRecordInfoRespDto;
import com.tian.dto.ChargeRecordListReqDto;
import com.tian.dto.ChargeRecordListRespDto;
import com.tian.entity.ChargeRecord;
import com.tian.mapper.ChargeRecordMapper;
import com.tian.service.ChargeRecordService;
import com.tian.util.CommonResult;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author tianwc  公众号：java后端技术全栈、面试专栏
 * @version 1.0.0
 * @date 2023年05月12日 15:14
 * 博客地址：<a href="http://woaijava.cc/">博客地址</a>
 */
@Service
public class ChargeRecordServiceImpl implements ChargeRecordService {

    @Resource
    private ChargeRecordMapper chargeRecordMapper;


    @Override
    public CommonResult<ChargeRecordListRespDto> page(ChargeRecordListReqDto chargeRecordListReqDto) {
        int count = chargeRecordMapper.count(chargeRecordListReqDto);
        if (count == 0) {
            return CommonResult.success(new ChargeRecordListRespDto());
        }
        List<ChargeRecord> chargeRecordList = chargeRecordMapper.page(chargeRecordListReqDto);
        List<ChargeRecordInfoRespDto> chargeRecordInfoRespDtoList = ChargeRecordConvertUtil.convert(chargeRecordList);

        ChargeRecordListRespDto chargeRecordListRespDto = new ChargeRecordListRespDto();
        chargeRecordListRespDto.setList(chargeRecordInfoRespDtoList);

        chargeRecordListRespDto.setStart(chargeRecordListReqDto.getStart());
        chargeRecordListRespDto.setPageSize(chargeRecordListReqDto.getPageSize());

        return CommonResult.success(chargeRecordListRespDto);
    }
}
